package com.taomu.app.zongchouhuli.utils;

import android.content.Context;
import android.view.WindowManager;

/**
 * Created by Snow on 2017/9/12.
 */

public class DpUtils {

    private static WindowManager windowManager;
    private static Context mContext;

    public static void init(Context context) {
        windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        mContext = context;
    }

    /**
     * dp2px
     *
     * @param dp
     * @return
     */
    public static int dp2px(Context context, int dp) {
        if (context == null) {
            throw new IllegalStateException("context must not be null!");
        }
        return (int) (context.getResources().getDisplayMetrics().density * dp + 0.5f);
    }

    /**
     * dp2px
     *
     * @param dp
     * @return
     */
    public static int dp2px(int dp) {
        return (int) (mContext.getResources().getDisplayMetrics().density * dp + 0.5f);
    }



    public static int screenHeight(){
        int height = windowManager.getDefaultDisplay().getHeight();
        return height;
    }

    public static int screnWidth(){
        int width = windowManager.getDefaultDisplay().getWidth();
        return width;
    }

}
